//
//  BuyNowViewController.m
//  PrintPort
//
//  Created by 华谕 on 2017/11/28.
//  Copyright © 2017年 HUAYU. All rights reserved.
//

#import "BuyNowViewController.h"
#import "HYManageAddressViewController.h"
#import "OrderModel.h"
#import "HYAddressModel.h"
#import "ImagelistModel.h"
#import "SizeListModel.h"
#import "SelectedSpecModel.h"
#import "SizeDetailModel.h"
#import "SYPasswordView.h"
#import "RetrievePasswordViewController.h"
#import "BuyBackPasswordViewController.h"

static NSString *cellPath = @"soureNowCell";
@interface BuyNowViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,PayPassWordDelegate>
@property (nonatomic, strong)SYPasswordView *pasView;
@property (nonatomic, strong)UIView *payPassView;
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)HYAddressModel *addressModel;
@property (nonatomic, strong)NSString *messageStr;
@property (nonatomic, strong)NSMutableArray *orderIdAry;
@property (nonatomic, strong)NSString *ggNameStr;
@property (nonatomic, assign)NSInteger payType;
@property (nonatomic, assign)BOOL isPay;

@end

@implementation BuyNowViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(Successnotice:) name:@"PaySuccess" object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PaySuccess" object:nil];
}

- (void)Successnotice:(NSNotification *)center
{
    if (!_isPay)
    {
        _isPay = YES;
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    _messageStr = @"";
    _payType = 0;
    [self getNameStr];
    [self creatUI];
    [self requestAddressLise];
}

- (void)getNameStr
{
    NSMutableDictionary *nameDic = [NSMutableDictionary dictionaryWithCapacity:0];
    NSArray *typeAry = _goodModel.productSizeList;
    for (SizeListModel *model in typeAry)
    {
        NSArray *ggAry = model.productSizeDetailList;
        NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
        for (SizeDetailModel *detaModel in ggAry)
        {
            [dic setObject:detaModel.productSizeDetailName forKey:detaModel.ID];
        }
        [nameDic setObject:dic forKey:model.ID];
    }
    _ggNameStr = @"";
    for (NSString *key in _goodsDic)
    {
        NSDictionary *typeDic = [_goodsDic objectForKey:key];
        NSDictionary *typePriceDic = [nameDic objectForKey:key];
        for (NSString *key22 in typeDic)
        {
            NSString *name = [typePriceDic objectForKey:key22];
            _ggNameStr = [NSString stringWithFormat:@"%@,",name];
        }
    }
    _ggNameStr = [_ggNameStr substringToIndex:_ggNameStr.length-1];
}
- (void)creatUI
{
    self.navigationItem.title = @"确认订单";
    self.view.backgroundColor = BacksColor;
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableview.backgroundColor = BacksColor;
    [self.view addSubview:_tableview];
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX, SCREEN_WIDTH, 50*displaywidth)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:whiteView];
    
    UILabel *tongjiLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, SCREEN_WIDTH-135*displaywidth, 40*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"共 1 件商品  合计：￥%.2lf元 + %.0lf积分",_zongPrice,_zongInteger] Color:RGB(77, 77, 77)];
    tongjiLab.textAlignment = NSTextAlignmentRight;
    [whiteView addSubview:tongjiLab];
    UIButton *settlemBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-100*displaywidth, 0, 100*displaywidth, 50*displaywidth) ImageName:nil Target:self Action:@selector(settlemAction) Title:@"结算" Font:16.0];
    settlemBtn.backgroundColor = ThemeColor;
    [settlemBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [whiteView addSubview:settlemBtn];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0)
    {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if (_addressModel)
        {
            UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 0, 70*displaywidth, 40*displaywidth) Font:14.0 Text:_addressModel.linkman Color:RGB(77, 77, 77)];
            [cell.contentView addSubview:titLab];
            UILabel *phoneLab = [ZCControl createLabelWithFrame:CGRectMake(90*displaywidth, 0, 160*displaywidth, 40*displaywidth) Font:14.0 Text:_addressModel.linkPhone Color:RGB(77, 77, 77)];
            [cell.contentView addSubview:phoneLab];
            UILabel *addressLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 40*displaywidth, SCREEN_WIDTH-50*displaywidth, 35*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@%@%@%@",_addressModel.provinceText,_addressModel.cityText,_addressModel.districtText,_addressModel.detailAddress] Color:RGB(77, 77, 77)];
            [cell.contentView addSubview:addressLab];
        }
        else
        {
            UILabel *tostLab = [ZCControl createLabelWithFrame:CGRectMake(30*displaywidth, 20*displaywidth, SCREEN_WIDTH-60*displaywidth, 40*displaywidth) Font:14.0 Text:@"请选择收货地址" Color:RGB(77, 77, 77)];
            tostLab.textAlignment = NSTextAlignmentCenter;
            [cell.contentView addSubview:tostLab];
        }
        
    }
    else if (indexPath.section == 1)
    {
        GoodsModel *goodsModel = _goodModel;
        UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 10*displaywidth, 80*displaywidth, 80*displaywidth) ImageName:@""];
        if (goodsModel.productImgList.count > 0)
        {
            ImagelistModel *imgModel = goodsModel.productImgList[0];
            [imgView sd_setImageWithURL:[NSURL URLWithString:imgModel.imgUrl]];
        }
        [cell.contentView addSubview:imgView];
        UILabel *titlab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 10*displaywidth, SCREEN_WIDTH-130*displaywidth, 25*displaywidth) Font:14.0 Text:[NSString stringWithFormat:@"%@",goodsModel.productName] Color:RGB(77, 77, 77)];
        titlab.lineBreakMode = NSLineBreakByTruncatingTail;
        [cell.contentView addSubview:titlab];
    
        NSString *typeStr = [NSString stringWithFormat:@"分类：%@",_ggNameStr];
        UILabel *typeLab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 35*displaywidth, SCREEN_WIDTH-130*displaywidth, 40*displaywidth) Font:12.0 Text:typeStr Color:RGB(179, 179, 179)];
        typeLab.lineBreakMode = UILineBreakModeTailTruncation;
        typeLab.adjustsFontSizeToFitWidth = NO;
        [cell.contentView addSubview:typeLab];
        UILabel *moneyLab = [ZCControl createLabelWithFrame:CGRectMake(115*displaywidth, 75*displaywidth, SCREEN_WIDTH-200*displaywidth, 20*displaywidth) Font:12.0 Text:[NSString stringWithFormat:@" ￥%.2lf",_zongPrice] Color:RGB(241, 90, 36)];
        CGRect abounds = [moneyLab.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-200*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(12.0+fontScale)} context:nil];
        CGFloat width1 = abounds.size.width+20;
        moneyLab.frame = CGRectMake(115*displaywidth, 75*displaywidth, width1, 20*displaywidth);
        [cell.contentView addSubview:moneyLab];
        if (!_isTH)
        {
            moneyLab.text = [NSString stringWithFormat:@" ￥%.2lf +",_zongPrice];
            UILabel *integralLab = [ZCControl createLabelWithFrame:CGRectMake(width1+120*displaywidth, 75*displaywidth, 120*displaywidth, 20*displaywidth) Font:11.0 Text:[NSString stringWithFormat:@"%@积分",goodsModel.integral] Color:[UIColor whiteColor]];
            integralLab.textAlignment = NSTextAlignmentCenter;
            integralLab.layer.cornerRadius = 2;
            integralLab.layer.masksToBounds = YES;
            integralLab.backgroundColor = RGB(24, 159, 186);
            [cell.contentView addSubview:integralLab];
            CGRect bounds1 = [integralLab.text boundingRectWithSize:CGSizeMake(120*displaywidth, 20*displaywidth) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:NormalFontWithSize(11.0+fontScale)} context:nil];
            CGFloat width2 = bounds1.size.width+10;
            if (bounds1.size.width > 120*displaywidth)
            {
                width2 = 120*displaywidth;
            }
            integralLab.frame = CGRectMake(width1+120*displaywidth, 75*displaywidth, width2, 20*displaywidth);
        }
        
    
        UILabel *numLab = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH-50*displaywidth, 75*displaywidth, 50*displaywidth, 20*displaywidth) Font:10.0 Text:[NSString stringWithFormat:@"x %ld",_zongNum] Color:RGB(179, 179, 179)];
        [cell.contentView addSubview:numLab];
            
//            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 100*displaywidth, SCREEN_WIDTH, 10*displaywidth)];
//            lineView.backgroundColor = BacksColor;
//            [cell.contentView addSubview:lineView];
        
    }
    else if (indexPath.section == 2)
    {
        UILabel *secondTitLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5, 80*displaywidth, 39*displaywidth) Font:13.0 Text:@"支付方式" Color:RGB(77, 77, 77)];
        [cell.contentView addSubview:secondTitLab];
        NSArray *imgAry = @[@"weixin",@"alipay"];
        NSArray *nameAry = @[@"微信支付",@"支付宝"];
//        NSArray *rightImgAry = @[@"yuand",@"xuankuang"];
        for (int i = 0; i < imgAry.count; i++)
        {
            UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(30*displaywidth, 60*displaywidth*(i+1), 30*displaywidth, 30*displaywidth) ImageName:imgAry[i]];
            imgView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imgView];
            UILabel *nameLabel = [ZCControl createLabelWithFrame:CGRectMake(95*displaywidth, 60*displaywidth*(i+1), SCREEN_WIDTH-130*displaywidth, 30*displaywidth) Font:13.0 Text:nameAry[i] Color:RGB(77, 77, 77)];
            [cell.contentView addSubview:nameLabel];
            UIImageView *imageView = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-35*displaywidth, 60*displaywidth*i+67.5*displaywidth, 15*displaywidth, 15*displaywidth) ImageName:@"xuankuang"];
            if (i == _payType)
            {
                imageView.image = IMAGE(@"yuand");
            }
            imageView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imageView];
            UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(0, 45*displaywidth+i*60*displaywidth, SCREEN_WIDTH, 60*displaywidth) ImageName:nil Target:self Action:@selector(closeTypeAction:) Title:nil Font:12.0];
            btn.backgroundColor = [UIColor clearColor];
            btn.tag = 100 + i;
            [cell.contentView addSubview:btn];
            UIView *lineview11 = [[UIView alloc] initWithFrame:CGRectMake(0, 44*displaywidth+i*60*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
            lineview11.backgroundColor = LinesColor;
            [cell.contentView addSubview:lineview11];
        }
    }
    else
    {
        UILabel *lytitLab = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 5*displaywidth, 70*displaywidth, 45*displaywidth) Font:14.0 Text:@"买家留言" Color:RGB(77, 77, 77)];
        [cell.contentView addSubview:lytitLab];
        UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(90*displaywidth, 5*displayheight, SCREEN_WIDTH-100*displaywidth, 45*displayheight) placeholder:@"" passWord:NO leftImageView:nil rightImageView:nil Font:14.0];
        [textfield setValue:RGB(204, 204, 204) forKeyPath:@"_placeholderLabel.textColor"];
        textfield.textColor = RGB(77, 77, 77);
        textfield.delegate = self;
        textfield.text = _messageStr;
        textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
        textfield.textAlignment = NSTextAlignmentRight;
        [cell.contentView addSubview:textfield];
        
    }
    if (indexPath.section != 0)
    {
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 5*displaywidth)];
        lineview.backgroundColor = LinesColor;
        [cell.contentView addSubview:lineview];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        HYManageAddressViewController *vc = [[HYManageAddressViewController alloc] init];
        vc.isFromOrder = YES;
        WEAKSELF;
        vc.addressBlock = ^(HYAddressModel *addreModel)
        {
            weakSelf.addressModel = addreModel;
            [weakSelf.tableview reloadData];
        };
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        return 80*displaywidth;
    }
    else if (indexPath.section == 1)
    {
        return 100*displaywidth;
    }
    else if (indexPath.section == 2)
    {
        return 165*displaywidth;
    }
    else
    {
        return 50*displaywidth;
    }
}

- (void)closeTypeAction:(UIButton *)btn
{
    NSInteger index = btn.tag-100;
    if (index != _payType)
    {
        _payType = index;
        [_tableview reloadData];
    }
}

//结算
- (void)settlemAction
{
    [self.view endEditing:YES];
    if (!_addressModel)
    {
        [LTools showMBProgressWithText:@"请选择收货地址" addToView:self.view];
        return;
    }
    [self requestOrderMaster];
}

- (void)requestAddressLise
{
    WEAKSELF;
    [HYBaseHandler requestAddressListParmers:nil Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSArray *addressAry = [HYAddressModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
            for (HYAddressModel *addressModel in addressAry)
            {
                if ([addressModel.isDefault integerValue] == 1)
                {
                    weakSelf.addressModel = addressModel;
                }
            }
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)requestOrderMaster
{
    WEAKSELF;
    NSMutableArray *SizeAry = [NSMutableArray arrayWithCapacity:0];
    for (NSString *key in _goodsDic)
    {
        NSDictionary *typeDic = [_goodsDic objectForKey:key];
        for (NSString *sizeid in typeDic)
        {
            NSString *numstr = [typeDic objectForKey:sizeid];
            NSInteger num = [numstr integerValue];
            if (num > 0)
            {
                NSDictionary *sizeDic = @{@"buySize":numstr,
                                          @"productSizeDetailId":sizeid
                                          };
                [SizeAry addObject:sizeDic];
            }
        }
    }
    NSDictionary *dic = @{@"addressId":_addressModel.ID,
                          @"buyerMsg":_messageStr,
                          @"clientId":@"4",
                          @"productSizeDetailList":SizeAry
                          };
    [HYBaseHandler requestWithJsonUrl:SERVER_NewOrderbuy Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSArray *orderIdAry = obj[@"data"];
//            NSMutableArray *idAry = [NSMutableArray arrayWithCapacity:0];
            if (orderIdAry.count > 0)
            {
                NSDictionary *idDic = orderIdAry[0];
                NSString *tradeNo = @"";
                if (_isTH)
                {
                    tradeNo = idDic[@"tradeNo"];
                }
                else
                {
                    tradeNo = idDic[@"commonTradeNo"];
                }
                PayManager *manage = [PayManager sharePayManager];
                [manage startNewPayRequest:_payType Pid:tradeNo];
            }
//            for (NSDictionary *idDic in orderIdAry)
//            {
//                NSString *tradeNo = idDic[@"commonTradeNo"];
//                [idAry addObject:tradeNo];
//            }
//            _orderIdAry = idAry;
            dispatch_async(dispatch_get_main_queue(), ^{
//                [weakSelf creatPayPassWordView];
            });
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
   
}

- (void)creatPayPassWordView
{
    if (!self.payPassView)
    {
        self.payPassView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        _payPassView.backgroundColor = RGBA(0, 0, 0, 0.5);
        [sharedDelegate.window addSubview:_payPassView];
        UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0, 230*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-230*displaywidth)];
        secondView.backgroundColor = RGB(242, 242, 242);
        [_payPassView addSubview:secondView];
        UILabel *titleLabel = [ZCControl createLabelWithFrame:CGRectMake(SCREEN_WIDTH/2-80*displaywidth, 0, 160*displaywidth, 44*displaywidth) Font:15.0 Text:@"请输入密码" Color:RGB(77, 77, 77)];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [secondView addSubview:titleLabel];
        UIButton *contactBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-60*displaywidth, 0, 44*displaywidth, 44*displaywidth) ImageName:@"chacha" Target:self Action:@selector(contactAction) Title:nil Font:13.0];
        contactBtn.backgroundColor = [UIColor clearColor];
        [secondView addSubview:contactBtn];
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 44*displaywidth, SCREEN_WIDTH, 1*displaywidth)];
        lineview.backgroundColor = RGB(210, 210, 210);
        [secondView addSubview:lineview];
        //        UILabel *moneyLabel = [ZCControl createLabelWithFrame:CGRectMake(15*displaywidth, 55*displaywidth, SCREEN_WIDTH-30*displaywidth, 25*displaywidth) Font:15.0 Text:@"充值金额 2000" Color:RGB(77, 77, 77)];
        //        moneyLabel.textAlignment = NSTextAlignmentCenter;
        //        [secondView addSubview:moneyLabel];
        self.pasView = [[SYPasswordView alloc] initWithFrame:CGRectMake(15*displaywidth, 90*displaywidth, SCREEN_WIDTH-30*displaywidth, 44*displaywidth)];
        _pasView.delegate = self;
        [secondView addSubview:_pasView];
        UIButton *forgotBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH-115*displaywidth, 150*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(FindPassword) Title:@"忘记密码" Font:13.0];
        [forgotBtn setTitleColor:RGB(255, 111, 28) forState:UIControlStateNormal];
        [secondView addSubview:forgotBtn];
    }
    _payPassView.hidden = NO;
    [_pasView.textField becomeFirstResponder];
}
- (void)shuruSuccessValue:(NSString *)value
{
    [self requestPublicKey:value];
    NSLog(@"密码-----%@",value);
}
- (void)requestPublicKey:(NSString *)passWorld
{
    WEAKSELF;
    [MBProgressHUD showHUDAddedTo:sharedDelegate.window animated:YES];
    [HYBaseHandler requestPublicKeyParmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             NSString *publicKey = obj[@"data"];
             //测试要加密的数据
             NSString *sourceStr = passWorld;
             //公钥加密
             NSString *encryptStr = [RSA encryptString:sourceStr publicKey:publicKey];
             [weakSelf requestWalletPay:encryptStr];
             
         }
         else
         {
             [self.pasView clearUpPassword];
             [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
             [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
     }];
}
//找回密码
- (void)FindPassword
{
    _payPassView.hidden = YES;
    [self.pasView endEditing:YES];
    [self.pasView clearUpPassword];
    BuyBackPasswordViewController *vc = [[BuyBackPasswordViewController alloc] init];
    vc.isPayPass = YES;
    vc.passType = @"4";
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)contactAction
{
    _payPassView.hidden = YES;
    [self.pasView endEditing:YES];
    [self.pasView clearUpPassword];
}

- (void)requestWalletPay:(NSString *)pass
{
    WEAKSELF;
    NSString *idStr = [_orderIdAry componentsJoinedByString:@","];
    NSDictionary *dic = @{@"tradeNo":idStr,
                          @"password":pass
                          };
    [HYBaseHandler requestWalletPayParmers:dic Success:^(id obj)
     {
         [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];
         if ([obj server_Getcodecheck])
         {
             [LTools showMBProgressWithText:@"支付成功" addToView:sharedDelegate.window];
             weakSelf.payPassView.hidden = YES;
             [weakSelf.pasView endEditing:YES];
             [weakSelf.pasView clearUpPassword];
             [weakSelf.payPassView removeFromSuperview];
             [weakSelf.navigationController popToRootViewControllerAnimated:YES];
         }
         else
         {
             [self.pasView clearUpPassword];
             [LTools showMBProgressWithText:obj[@"msg"] addToView:sharedDelegate.window];
         }
     } failed:^(NSError *error) {
         [MBProgressHUD hideAllHUDsForView:sharedDelegate.window animated:YES];

     }];
}



- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    _tableview.frame = CGRectMake(0, -80, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX);
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    _messageStr = textField.text;
    _tableview.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-50*displaywidth-SCREER_HeiX);
}

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    [self.view endEditing:YES];
    return indexPath;
}
// 滑动的时候 searchBar 回收键盘

- (void)scrollViewWillBeginDragging:(UIScrollView*)scrollView
{
    [self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
